package filesystem;

import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;

import javax.swing.ImageIcon;

/**
 * Utility class responsible for loading icons from the classpath
 * 
 * @author Renat Zubairov, Igor Drobiazko
 */
public class Utils {

	/**
	 * Get the icon from classpath
	 * 
	 * @param iconName
	 *            name of the icon
	 */
	public static ImageIcon getIcon(Object iconName) {
		String classPathLocation = "/icons/" + String.valueOf(iconName);
		URL url = Utils.class.getResource(classPathLocation);
		if (url != null) {
			Image image = Toolkit.getDefaultToolkit().getImage(url);
			return new ImageIcon(image, url.toString());
		} else {
			throw new IllegalArgumentException("Can't find icon " + iconName);
		}
	}
}
